Hello I want to make a stair light using a Arduino UNO and two ultrasonic sound sensors but when I simulate using Tinkercad the LEDstrips turn on when i set the sensor lower than 80cm but then they dont turn off when i turn the sensor above 80cm.
This is the code i have for now, i am going to add a fade and another sensor but i want to test the turn on turn of thingy
#include <Adafruit_NeoPixel.h>
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 2
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 8
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
void setup() {
// Initialize the NeoPixel library.
strip.begin();
}
void loop() {
uint32_t wit = strip.Color(255, 251, 230);
strip.fill(wit, 0, 8);
if (0.01723 * readUltrasonicDistance(3, 3) < 80) { strip.show();
}
{delay(10);
}
if (0.01723 * readUltrasonicDistance(3, 3) > 80) { strip.clear();
}
}