Light Sensing MP3 Player using Adafruit's Beginner Arduino Solder-Free Kit

게시자

The Beginner's Arduino Solder-Free Kit comes with everything you need to create an MP3 player, but JJ took it a step further by adding a Vishay ambient light sensor to the mix.

From the box, we got the Adafruit music maker playing the music.

관련 상품 참조

3208

Adafruit Industries Embedded System Development Boards and Kits 보기

Let's create our own application where the played music will depend on ambient light. The VEML6030 from Vishay is used as the ambient light sensor to give us the number of lux. The data is obtained through an I2C bus.

관련 상품 참조

VEML6030

Vishay Ambient Light Sensors 보기

Even if Arduino makes the programmation of the I2C bus very easy, it is necessary to understand the basics in order to program it.

The I2C bus is a standard widely used for sensors. It was designed by Philips (called NXP today) and works with only 2 lines : one line for the clock (called SCL) and one line for data (called SDA). This last line is bidirectional. These teo lines are open drain and need pull up resistors. These are the resistors you see on the breadboard. Obviously, on a final application, you design these resistors on your board. The master of the bus generates the clock and initiates communication with the slave. Each slave device has a 7-bit address.

관련 상품 참조

PCF8584T/2,512

NXP Semiconductors Interface Controllers 보기

The protocol is the following: the master sends a start bit (that is a high to low transition of SDA with SCL high) followed by the 7-bit address of the address it wished to communicate with, then followed by a single bit if it wishes to write (bit at 0) or to read (bit at one) from the slave. After each 8-bit transmission, the slave responds with an ACK bit (SDA is put low). If the transmitter sees a bit 1, it a NACK (not Acknowledged)

The end of the communication corresponds to a STOP bit. It is a low-to-high transition of SDA with SCL high. As Start and Stop bit occur when SCL high, all other transition of SDA take place with SCL low.

Now we understood how I2C works, we read the data in the datasheet of the VEML6030 to know the values to write in our program.

First, reading the schematic of the VEML6030, we can see an address pin allows configuring the address value. On our board, this pin is grounded, that means the address of the device is 0x10.

The datasheet explains the I2C interface and how to send commands. When we need to write to the device, we need to send the address, the command code. In the VEML6030, all the registers are 16 bits and the LSB must be first. So, we want to configure the VEML6030 with a gain of one quarter, integration time of 100ms and we need to power on the ambient light sensor, the LSB is equal to 0x00 and the MSB is equal to 0x18. In our program we defined the micros, include the wire library, in the setup, Wire.begin() is called, then in the loop function, we begin a transmission with the address of the VEML6030, the register command (0x00 in the present case) we send the LSB and MSB and finally and endTransmission. To have deeper explanation of these commands, you can go on Arduino web site where libraries are explained. 

Similar way to read the data. we begin a transmission, send the register value where we want to read the data, requestFrom function with the address and 2 bytes to read and finally we read the data.

We convert the lux level in an integer and we finally decide which music to play depending on the lux value.

If below 20, we play a music to sleep. Between 20 and 50 lux, a music to relax, between 50 and 800, a music for an active life, and above 800, we image you are outside for a party and ready for techno music.

You are now ready to create your own app with any kind of sensors and customize your music player.

최신 동영상

죄송합니다. 선택한 필터와 일치하는 결과가 없습니다.

개인정보 보호정책이 업데이트되었습니다. 잠시 시간을 내어 변경사항을 검토하시기 바랍니다. 동의를 클릭하면 Arrow Electronics 개인정보 보호정책 및 이용 조건에 동의하는 것입니다.

당사의 웹사이트에서는 사용자의 경험 향상과 사이트 개선을 위해 사용자의 기기에 쿠키를 저장합니다. 당사에서 사용하는 쿠키 및 쿠키 비활성화 방법에 대해 자세히 알아보십시오. 쿠키와 추적 기술은 마케팅 목적으로 사용될 수 있습니다. '동의'를 클릭하면 기기에 쿠키를 배치하고 추적 기술을 사용하는 데 동의하는 것입니다. 쿠키 및 추적 기술을 해제하는 방법에 대한 자세한 내용과 지침을 알아보려면 아래의 '자세히 알아보기'를 클릭하십시오. 쿠키 및 추적 기술 수락은 사용자의 자발적 선택이지만, 웹사이트가 제대로 작동하지 않을 수 있으며 사용자와 관련이 적은 광고가 표시될 수 있습니다. Arrow는 사용자의 개인정보를 존중합니다. 여기에서 당사의 개인정보 보호정책을 읽을 수 있습니다.