Potentiometer

Liam Brady

Potentiometers are variable resistors. Potentiometers have a knob that varies the output voltage (by varying the resistance as they are turned). The analog pins on the Arduino can measure this change.

void setup() {
  Serial.begin(9600);
}

void loop() {
  int val = analogRead(A0);

  Serial.println(val);

  delay(100);
}

Force Sensor

Liam Brady

Force sensors are sensors that change resistance based on how much force is applied on it. The more force applied, the lower the resistance. Force can be measured using the analog pins on the Arduino.

void setup() {
  Serial.begin(9600);
}

void loop() {
  int val = analogRead(A0);

  Serial.println(val);
}

NeoPixel LED Strip

Liam Brady

LED Strips are individually addressable ribbons of RGB (red green blue) lights, meaning that each light on the ribbon can be controlled by itself and give off any color on the visible color spectrum. Every light on the strip has its own chip onboard that processes commands given to it by the Arduino.


#include <FastLED.h>
#define NUM_LEDS 15
#define DATA_PIN 6

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
  

leds[0] = CRGB::Red; 

        FastLED.show(); 

        delay(30); 

}

#include <FastLED.h>

#define PIN 10

#define NUM_LEDS 15


CRGB leds[NUM_LEDS];


void setup() {

  // put your setup code here, to run once:

  FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);

}


void loop() {


  int potPin = analogRead(A0);


  int pixelPos = map(potPin,0,1024,0, NUM_LEDS);


  for (int dot = 0; dot < pixelPos; dot++) {

    leds[dot] = CHSV( 255, 255, 255);

    FastLED.show();

    // clear this led for the next time around the loop

    leds[dot] = CRGB::Black;

  }

}

Ultrasonic Sensor (Large)

Liam Brady

Ultrasonic sensors are distance sensors that use sound waves to detect how far away an object is. They send out high frequency bursts of sound and listen for its echo. They then determine how far away the object is based on how long it takes for the sound to return to the sensor. This variety requires an Arduino library to operate.

 

NewPing Library

#include <NewPing.h>

NewPing mysensor(5, 6, 200);

void setup() {
  Serial.begin(9600);
}

void loop() {
  int pingTime = mysensor.ping();

  int distance = mysensor.ping_in();

  int distance_cm = mysensor.ping_cm();

  Serial.println(distance);
}