ใช้ Arduino Pro Mini โดยมีชิป AtMega 168 มาใช้ทำสวิทช์รับแสง ถ้าแสงสว่างจะเป็นการสั่งปิดไฟ ถ้าแสงมืดลง จะเป็นการสั่งให้ไฟเปิด
บอร์ดตัวนี้สั่งมาจาก Shopee ซึ่งเป็นร้านอยู่ในประเทศจีน ราคาแผ่นละ 38 บาท
ตัวบอร์ด เมื่อขยายดูแล้ว จะมีลักษณะดังภาพ
ตัว source code เป็นดังนี้
int lightPin = 0; //pin for Photoresistor
int TranslateAnalog = 0;
int CutPoint = 18;
void setup(){
// Serial.begin(9600); //Start serial communication
pinMode (7, OUTPUT);
}
void loop()
{
// Serial.println(analogRead(lightPin));
//Write the value of the photoresistor to the serial monitor.
TranslateAnalog = analogRead(lightPin);
//Read the Photoresistor value
//If Photoresistor Value is above CutPoint it will disable LED
if(TranslateAnalog>CutPoint) {
digitalWrite(7, LOW);
}
//If Photoreistor Value is below CutPoint it will turn LED ON
if(TranslateAnalog<CutPoint) {
digitalWrite(7, HIGH);
// Serial.println(analogRead(lightPin));
}
delay(10); //10 miliseconds delay
}
โดยตัว Arduino Pro Mini นั้นจะไม่มี port USB ให้ใช้สำหรับการโอนถ่ายข้อมูล เราจึงต้องมีตัวแปลงมาต่อเพื่อให้ส่งข้อมูลผ่าน USB port ได้ โดยตัวนี้จะเรียกว่า CP 2102 Chips Micro USB 2.0 to TTL Module UART 6 Pin Serial Converter สั่งซื้อจาก Shopee ตอนนั้นราคาแผ่นละ 33 บาท (เช็คล่าสุด 46 บาท)
โดยทางฝั่งตัว Adapter จะต่อสายแบบนี้
และทางฝั่ง Arduino จะต่อสายแบบนี้ สายสีเหลืองไม่ได้ใช้ เพราะเป็นไฟ 3.3 v
จากนั้นก็ upload code จากโปรแกรม Arduino IDE เข้าตัวบอร์ดได้เลย ตัวที่ประกอบเสร็จแล้ว จะเป็นดังภาพ