In this tutorial we will be using mini reed switch/sensor (KY-021). We are going to program our surilli with a basic program so we can detect magnetic field.
Mini reed switch/sensor (KY-021):This is a small device called a reed switch. When the device is exposed to a magnetic field, the two ferrous materials inside the switch pull together and the switch closes. When the magnetic field is removed, the reeds separate and the switch opens or vice versa.
A relay, another electro-mechanical device, is comprised of a reed switch and an electromagnet trigger built into one housing. Common uses for reed switches(not counting relays which are used in virtually all electronic devices) include the 'pick ups' on bicycle computers and the sensors on window and door alarms.
Make sure you have selected the right port, board and processor for the Surilli and it is programmable (compile and upload “Blink”fromFile>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 2: The circuitry:The circuitry is very simple. It's mostly the programming, follow the Figure 1 to setup your hardware.
- Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
- After it is uploaded, the sensor will start working.
int Led = 5 ;// define LED Interface
int buttonpin = 4; // define the Reed sensor interfaces
int val ;// define numeric variables val
void setup ()
{
pinMode (Led, OUTPUT) ;// define LED as output interface
pinMode (buttonpin, INPUT) ;// output interface as defined Reed sensor
}
void loop ()
{
val = digitalRead (buttonpin) ;// digital interface will be assigned a value of 4 to read val
if (val == HIGH) // When the Reed sensor detects a signal, LED flashes
{
digitalWrite (Led, LOW);
}
else
{
digitalWrite (Led, HIGH);
}
}
Play with theprogram to see how it reacts to different values and logic. This will developyour understanding about light cup sensors so you can use them in yourpractical application.
If you makesomething fun and interesting do share it with our community :)
That’s all fornow. If you have any queries, visit surilli.io or contact our support. Stay connectedwith Surilli family for more amazing stuff :)
Comments