keyestudio
Connect the controller board, shield, breadboard and USB cable according to Arduino tutorial.
Connect the LED to digital pin 8, ball switch to analog pin 5.
Experiment principle
When one end of the switch is below horizontal position, the switch is on. The voltage of the
analog port is about 5V (1023 in binary). The LED will be on. When the other end of the switch is
below horizontal position, the switch is off. The voltage of the analog port is about 0V (0 in
binary). The LED will be off. In the program, we determine whether the switch is on or off
according to the voltage value of the analog port, whether it's above 2.5V (512 in binary) or not.
Sample program
//////////////////////////////////////////////////////////
void setup()
{
pinMode(8,OUTPUT);// set digital pin 8 as "output"
}
void loop()
{
int i;// define variable i
while(1)
www.keyestudio.cc
81
Need help?
Do you have a question about the ARDUINO maker learning kit and is the answer not in the manual?