introduction
A metal touch sensor is a type of sensor that generates signals when touched by any charged object. it has a transistor-like element which sensor the external touch on it, based on thee signal generated we can use this sensor as a switch or any other application.
Circuit
Code
- Add an “if” block from the controls palette into the scripting area.
- From the Arduino sensor palette, add “read digital sensor () at pin()” inside the “if” block. Choose “touch sensor” from the drop-down menu
- Create a variable and name it “count.” Increment the count by 1 inside the “if” block, which helps keep track of touch interactions.
- Now use an “if then else” block inside the “if” block to check whether the count variable is even or odd. The modulo (mod) block from the Arduino palette can be utilized for this purpose.
- Based on the condition, control the LED to turn it ON for even counts and OFF for odd counts.
- Add the “set digital pin () output as ()” block from the Arduino palette within the “if” and “else” blocks, respectively.
- Set the “count” variable to 0 at the beginning of the code to ensure accurate counting from the start.
- Add a “when flag clicked” block from the events palette to initiate the code execution.
Script
Output