Day 08 // ELECTRONICS

Ultrasonic Sensor (Large)

Liam Brady and Shaunta Butler

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 https://libraries.io/github/PaulStoffregen/NewPing

#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);
}

Servo

Liam Brady and Shaunta Butler

Servos are specialized motors that support precise control. Rather than spinning off to oblivion like a motor, servos let the designer specify exactly where they want the object to rotate to. Most common servos allow for 180º of rotation.

#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  int val = analogRead(A0);
  val = map(val, 0, 1023, 0, 179);

  myservo.write(val);

  delay(15);
}

NeoPixel LED Strip

Liam Brady and Shaunta Butler

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.

 

NeoPixel Library

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, 6, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
}

void loop() {
  for (int i = 0; i < strip.numPixels();  i++) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
  }

  strip.show();

  delay(100);
}

Color Sensor

Liam Brady

Color sensors are series of photodiodes that can detect the amount of red, green, and blue light it is seeing. The version NuVu uses is Adafruit’s TCS34725 color sensor, and it interfaces with Arduinos using a library.

 

TCS34725 Library

#include <Wire.h>
#include "Adafruit_TCS34725.h"

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

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


void loop() {
  uint16_t r, g, b, c;

  tcs.getRawData(&r, &g, &b, &c);

  Serial.println(r);
  Serial.println(g);
  Serial.println(b);
}

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);
}

Flex Sensor

Liam Brady

Flex sensors are resistance-based sensors that react to how much they get bent. The more they are bent, the larger the resistance across the sensor. The Arduino is able to measure the changing resistance to determine how much the sensor is bent.

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

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

  Serial.println(val);
  delay(100);
}