XIANGYI XIA
Published

Powering with Love-Automatic Sensor Crossing Light

Be a warm light in your dark night

BeginnerFull instructions provided1 hour206
Powering with Love-Automatic Sensor Crossing Light

Things used in this project

Story

Read more

Schematics

Connecting all the components

Code

All the code for this project

C/C++
#include <Ultrasonic.h>
#include "Adafruit_NeoPixel.h"
Ultrasonic ultrasonic(A0);// Set PIN

int ledstripPin = A3;// Set PIN
int intnumber;
#define NUMPIXELS      48 // Set # of Pixels 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, ledstripPin, NEO_GRB + NEO_KHZ800);

 
int delayval = 1;
void setup() {
  Serial.begin(9600);
  pinMode(A3,OUTPUT);
  pinMode(A0,INPUT);
 
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  pixels.setBrightness(150);
  pixels.begin();
}

void loop() {

long sensorvalue;
long MeasureIn;



  sensorvalue = ultrasonic.MeasureInCentimeters();

 int sensor = (int)sensorvalue;
  Serial.print("cm");
  Serial.println(sensorvalue);
  Serial.println(sensor);
  if(sensor<30){ // Set your Range : Example:I set the range in 30CM
    
     for(int i=0;i<NUMPIXELS;i++){
 
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(50,100,50)); // Moderately bright green color.
 
    pixels.show(); // This sends the updated pixel color to the hardware.
 
    delay(delayval);
    Serial.println("1");
  }
  }
  else if(sensor>30){// Set your Range : Example:I set the range in 30CM

    
 for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
 
    pixels.show(); 
 
    delay(delayval);
    Serial.println("2");
 }
  }



}

Credits

XIANGYI XIA
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.