Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Frances Hudson
Created October 31, 2023

Enviro-friendly Community Library

The Enviro-friendly Community Library is a solar-powered and musical free library made primarily of recycled materials.

19
Enviro-friendly Community Library

Things used in this project

Hardware components

SparkFun RedBoard
SparkFun RedBoard
×1
Buzzer
Buzzer
×1
SparkFun Button
×1
Jumper wires (generic)
Jumper wires (generic)
×1
SparkFun Mini Solar Panel - 0.3 watt, 6 volt (ETFE)
×2
Door Hinge
×1
Assembly Hardware, Handle Assembly
Assembly Hardware, Handle Assembly
×1
SparkFun Serial Enabled LCD Kit
SparkFun Serial Enabled LCD Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Handsaw
Hammer
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Tape, Electrical
Tape, Electrical

Story

Read more

Schematics

Sorry!

Code

Redboard Code for Enviro-friendly Community Library

C/C++
The attached code is uploaded to a SparkFun Redboard, which serves as the "brain" of my project. This code prints out statements to the LCD screen and plays a short song that I wrote on a piezoelectric buzzer when the button is pressed. Note: I used a public domain section of code originally written by David A. Mellis to set up the LCD screen. This code is heavily modified, and any changes are entirely my own work. I was looking at adding a random number generate to make it so that one of a handful of tunes is chosen to play each time the button is pressed. I left some of the code I was working on for this behind //'s since I would like to come back to it later.
/*LCD-Hello_world.ino

 Modified By: Ho Yun "Bobby" Chan
 SparkFun Electronics
 Date: 5/22/2019
 License: This code is public domain.

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time since the Arduino was turned on.

  Hardware Hookup:

    lCD VSS pin to GND
    LCD VCC pin to 5V
    10k Potentiometer to LCD VO pin (pin 3)
    LCD RS pin to digital pin 13
    LCD R/W pin to GND
    LCD Enable pin to digital pin 12
    .
    .
    .
    LCD D4 pin to digital pin 11
    LCD D5 pin to digital pin 10
    LCD D6 pin to digital pin 9
    LCD D7 pin to digital pin 8
    LCD-Backlight - Anode to 10K resistor to +5V (optional depending on your LCD)
    LCD Backlight - K to GND

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld=

https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide

*/

// include the library code:
#include <LiquidCrystal.h>

//initialize the library by associating any needed LCD interface pin
//with the arduino pin number it is connected to
const int buttonPin = 2;
const int tonePin = 3;
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

long randNumber;
int buttonState = 0;
int y = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  //set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  //randomSeed(analogRead(0));
  //Print a message to the LCD.
  lcd.print("Solar Powered!");
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  //set the cursor to column 0, line 1
  //(note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  if (buttonState == HIGH) {
    delay(1000);
    lcd.clear();
    lcd.print("Playing...");
    //randNumber = random(0,3);
    //Serial.println(randNumber);
    lcd.setCursor(0,1);
    //lcd.print(randNumber);
    //if (randNumber == 0) {
      tone(3, 523.25, 225);
      delay(250);
      tone(3, 440, 225);
      delay(250);
      tone(3, 523.25, 225);
      delay(250);
      tone(3, 698.46, 225);
      delay(250);
      tone(3, 523.25, 225);
      delay(250);
      tone(3, 440, 225);
      delay(250);
      tone(3, 523.25, 225);
      delay(250);
      tone(3, 659.25, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 440, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 659.25, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 440, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 659.25, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 440, 225);
      delay(250);
      tone(3, 554.37, 225);
      delay(250);
      tone(3, 659.25, 400);
      delay(500);
      tone(3, 880, 400);
      delay(500);
      tone(8, 698.46, 225);
      //
      delay(250);
      tone(8, 587.33, 225);
      delay(250);
      tone(8, 698.46, 225);
      delay(250);
      tone(8, 1046.50, 225);
      delay(250);
      tone(8, 659.25, 225);
      delay(250);
      tone(8, 554.37, 225);
      delay(250);
      tone(8, 880, 225);
      delay(250);
      tone(8, 1108.73, 225);
      delay(250);
      tone(8, 2349.32, 900);
      delay(1000);
      tone(8, 110, 900);
      delay(1000);
    }
    
    
  else {
    int x = 0;
    lcd.setCursor(0,0);
    lcd.print("Solar Powered");
    lcd.setCursor(0, 1);
    lcd.print("Press here! -->");
    //x = x + (millis()/1000) - y;
    //lcd.print(x);
    noTone(3);
  }
}

Credits

Frances Hudson

Frances Hudson

1 project • 0 followers

Comments